#include "../../head.h"

int main()
{
    if (access("/home/jinyu/read",F_OK) == -1 && access("/home/jinyu/write",F_OK) == -1)
    {
        mkfifo("/home/jinyu/read",0666);
        mkfifo("/home/jinyu/write",0666);
    }
    else
    {
        printf("文件已存在\n");
    }

    int fd = open("/home/jinyu/write",O_WRONLY);
    int fp = open("/home/jinyu/read",O_RDONLY);
    
    pid_t pid = fork();

    if (pid == 0)
    {
        char output[32] = {0};
        while (1)
        {
            read(fp,output,sizeof(output));
            if (strcmp(output,"exit") == 0)   
            {
                break;
            }
            printf("%s\n",output);
        }
    }
    if (pid > 0)
    {
        char input[32] = {0};
        while (1)
        {
            scanf("%s",input);
            write(fd,input,sizeof(input));
            if (strcmp(input,"exit") == 0)
            {
                break;
            }
        }
        wait(NULL);     
    }

}